<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sort array maintaining index association</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.collator.html">Collator</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="collator.compare.html">Collator::compare</a></div>
 <div class="up"><a href="class.collator.html">Collator</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="collator.asort" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Collator::asort</h1>
  <h1 class="refname">collator_asort</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Collator::asort</span> -- <span class="refname">collator_asort</span> &mdash; <span class="dc-title">Sort array maintaining index association</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-collator.asort-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span> 
   <span class="methodname"><strong>Collator::asort</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$arr</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$sort_flag</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> 
   <span class="methodname"><strong>collator_asort</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.collator.html" class="type Collator">Collator</a></span> <code class="parameter">$coll</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$arr</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$sort_flag</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   This function sorts an array such that array indices maintain their
   correlation with the array elements they are associated with. This is used
   mainly when sorting associative arrays where the actual element order is
   significant. Array elements will have sort order according to current
   locale rules.
  </p>
  <p class="para">
   Equivalent to standard PHP
   <span class="function"><a href="function.asort.html" class="function">asort()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-collator.asort-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">coll</code></em></dt>

     <dd>

      <p class="para">
       <a href="class.collator.html" class="classname">Collator</a> object.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">arr</code></em></dt>

     <dd>

      <p class="para">Array of strings to sort.</p>
     </dd>

    
    
     <dt>
<em><code class="parameter">sort_flag</code></em></dt>

     <dd>

      <p class="para">
       Optional sorting type, one of the following:
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::SORT_REGULAR</code></strong>
          - compare items normally (don&#039;t change types)
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::SORT_NUMERIC</code></strong>
          - compare items numerically
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::SORT_STRING</code></strong>
          - compare items as strings
         </p>
        </li>
       </ul>
      </p>
      <p class="para">
       Default $sort_flag value is
       <strong><code>Collator::SORT_REGULAR</code></strong>.
       It is also used if an invalid $sort_flag value has been specified.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-collator.asort-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-collator.asort-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2423">
    <p><strong>Example #1 <span class="function"><strong>collator_asort()</strong></span>example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$coll&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">collator_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'en_US'&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'a'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'100'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'b'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'50'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'c'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'7'<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">collator_asort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Collator</span><span style="color: #007700">::</span><span style="color: #0000BB">SORT_NUMERIC&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">collator_asort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Collator</span><span style="color: #007700">::</span><span style="color: #0000BB">SORT_STRING&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array (
  &#039;c&#039; =&gt; &#039;7&#039;,
  &#039;b&#039; =&gt; &#039;50&#039;,
  &#039;a&#039; =&gt; &#039;100&#039;,
)array (
  &#039;a&#039; =&gt; &#039;100&#039;,
  &#039;b&#039; =&gt; &#039;50&#039;,
  &#039;c&#039; =&gt; &#039;7&#039;,
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-collator.asort-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="class.collator.html#intl.collator-constants" class="link"><a href="class.collator.html" class="classname">Collator</a> constants</a></li>
    <li class="member"><span class="function"><a href="collator.sort.html" class="function" rel="rdfs-seeAlso">collator_sort()</a> - Sort array using specified collator</span></li>
    <li class="member"><span class="function"><a href="collator.sortwithsortkeys.html" class="function" rel="rdfs-seeAlso">collator_sort_with_sort_keys()</a> - Sort array using specified collator and sort keys</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.collator.html">Collator</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="collator.compare.html">Collator::compare</a></div>
 <div class="up"><a href="class.collator.html">Collator</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
